'''
    存放：
    1、算法用到的全局变量
    2、tkinter用到的交互变量
    3、web用到的可视化变量
    4、class Memory：模拟内存

    MAX = 50 ：内存最大 50
    a[]:输入数据
    bn ：分配的内存块
    dataNum：数据输入量
    Time[]：每个内存块都对应一个计数器
    Time_pos :计数器指针
    Time_count ：计数器时钟源
'''
MAX = 50
a = []
bn = 0
dataNum = 0
Time = []
Time_pos = 0
Time_count = 0
'''
tkinter 交互变量
'''
put0_string = ''
put1_string = ''
put2_string = ''
put3_string = ''
put4_string = ''
put5_string = ''
res6_string = ''
res7_string = 0
res8_string = 0
order = ''
identity = 0
userInfo = {}
'''
web可视化交互变量
'''
class OPT:
    PMCount = 0
    RCount = 0
    Rate = 0.0

class FIFO:
    PMCount = 0
    RCount = 0
    Rate = 0.0
'''
模拟内存
'''


class Memory(object):

    '''
    不满返回空闲块号
    '''
    def isFull(self):
        if self.pos >= bn:
            return -100
        else:
            return self.pos
    '''
    返回缺页中断次数
    '''
    def getRMCount(self):
        return self.PMCount

    '''
    返回置换次数
    '''
    def getRCount(self):
        return self.RCount
    '''
    更新中断次数
    '''
    def upRMCount(self):
        self.PMCount =self.PMCount+1

    '''
    更新置换次数
    '''
    def upRCount(self):
        self.RCount =self.RCount+1

    '''
    返回所有内存块数据
    '''
    def getBlocks(self):
        print(self.block)
        return self.block
        # for i in range(bn):
        #     print( self.block[i],end="" )
        # print()

    '''
    返回某个内存块内容
    '''
    def getblock(self,i):
        return self.block[i]
    '''
    更新内存块内容
    '''
    def updateblock(self,i,content):
        self.block[i] = content
    '''
    内存块初始化
    输入数据均不小于0
    memset(block, -1, sizeof(block))
    '''
    def init_M(self):
        self.pos = 0
        self.PMCount = 0
        self.RCount = 0
        for i in range(bn):
            self.block[i] = -1
    '''
    内存块销毁
    '''
    def destory(self):
        self.block = []
    '''
    内存指针、
    中断次数、
    置换次数、
    内存块
    '''
    pos = 0
    PMCount = 0
    RCount = 0
    block = []
